<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<script type="text/javascript">
  var initDistributeOptions;
  $(function(){
    var data= getDetailInfo("/sysUserController/detailUser.html",$('#userIdFrom').text());
    var ids = [];
    if(data.departmentHead){
      ids = data.departmentHead.split(",");
    }
    var initOptions = {
      singleSelect:false,
      frozenColumns: [[
        {
          title: '编号',
          width: 150,
          checkbox: true
        },{
          field: 'id',
          title: '部门代码',
          width: 100
        },
        {
          field: 'deptName',
          title: '部门名称',
          width: 100
        }, {
          field: 'deptType',
          title: '业务单元类型',
          width: 100
        }]],
      onLoadSuccess:function(row){//当表格成功加载时执行
        var rowData = row.rows;
        $.each(rowData,function(idx,val){//遍历JSON
          $.each(ids, function(index){
            if(ids[index] == val.id){
              $('#dataGridDept').datagrid("selectRow", idx);
            }
          });
        });
      }
    }
    initAjaxDataGrid("/deptController/deptList.html", $('#dataGridDept'), initOptions);

    $('#grantsFunction').click(function () {
      var nodesObj = $('#dataGridDept').datagrid('getChecked');
      //TODO
      var idArray = new Array();
      $.each(nodesObj,function(index, node){
        idArray.push(node.id +"");
      });
      var postData = {
        id:$('#userIdFrom').text(),
        departmentHead:idArray.toString()
      }
      $.ajax({
        url: "${pageContext.request.contextPath}/sysUserController/updateUser.html",
        type: "post",
        dataType: "json",
        data: postData,
        success: function (result) {
          parent.$.messager.progress('close');
          if (result && isSuccess(result.result)) {
            parent.$.modalDialog.handler.dialog('close');
          }else{
            parent.$.messager.alert('提示', result.result + " " + result.message, 'info');
          }
          return false;
        },
        error: function (result) {
//			internalError();
          templateInternalError(result.responseText);
          parent.$.messager.progress('close');
          return false;
        }
      });
    });

  })
</script>
<var id="userIdFrom" style="display: none">${userId}</var>
<%--<var id="responseDept" style="display: none">${responseDept}</var>--%>
<div class="easyui-layout" data-options="fit:true,border:false">
  <div data-options="region:'center',border:false" title="" style="overflow: hidden;">
    <table id="dataGridDept"></table>
  </div>
</div>
</div>
